package com.bzyd.cloud.fallback;

import com.bzyd.cloud.feign.ProductService;
import com.bzyd.cloud.pojo.Product;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 容错类工厂
 * Created by Xianyue Dang on 2021/8/18
 */
@Component
public class ProductServiceFallBackFactory implements FallbackFactory<ProductService> {
    @Override
    public ProductService create(Throwable throwable) {
        return new ProductService() {
            @Override
            public Product findById(Integer pid) {
                throwable.printStackTrace();
                Product product = new Product();
                product.setPid(-1);
                return product;
            }

            @Override
            public void reduceInventory(Integer pid, int num) {

            }
        };
    }
}
